# -
# import os
# os.environ["OPENCV_IO_MAX_IMAGE_PIXELS"] = pow(2, 40).__str__()
# 以上两行用于解除opencv读取图像大小限制
import cv2
from ImCutMerge import im_cut_merge  # 导入处理类
from ImCutMergeByWindow import imc


def exception_process(message):
    # 示例错误处理函数
    print(message)


def clip_process(temp_img):
    # 示例回调函数
    cv2.line(temp_img, (0, 0), (0, temp_img.shape[1]), (0, 0, 255), 2)
    cv2.line(temp_img, (0, temp_img.shape[0]), (temp_img.shape[0], temp_img.shape[1]), (0, 0, 255), 2)
    return temp_img


def cut_to_dir(img):
    im_cut_merge.set_exception_process(exception_process)
    im_cut_merge.img_cut(img, 30, 30)
    image2 = im_cut_merge.img_merge_dir()
    cv2.imshow("from dir", image2)


def cut_to_memory(img):
    im_cut_merge.set_exception_process(exception_process)
    image1 = im_cut_merge.img_cut(img, 70, 70, clip_process)
    cv2.imshow("image", image1)


def cut_merge_window():
    """
    滑动窗口方式
    """
    image = cv2.imread("test01.jpg")
    imc.img_cut(image, 300, 300, 50, 50, clip_file_type=".jpg")
    img = imc.img_merge()
    cv2.imshow("img", img)
    cv2.waitKey()


def get_test_img(img_t, top, bottom, left, right):
    # 获取大图中的部分区域
    img_t = img_t[top:bottom, left:right]
    cv2.imshow("%s_%s_%s_%s" % (top, bottom, left, right), img_t)
    cv2.waitKey()


if __name__ == '__main__':
    """
     此处为ImCutMergeByWindow的使用示例
    """
    image = cv2.imread("img.tif")
    imc.img_cut(image, 700, 700, 200, 200, clip_file_type=".jpg")
    img = imc.img_merge()
    cv2.imwrite("img.tif", img)
    print("finished")
    cv2.waitKey()
#
# #cut_to_dir(image)
# cut_to_dir(image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
